<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>fetch发送Ajax请求</title>
</head>

<body>
  <button>GET</button>
  <button>POST</button>

  <script>
    let btns = document.querySelectorAll('button')

    btns[0].onclick = function () {
      fetch('http://127.0.0.1:8000/fetch-server', {
        method: 'get',
      })
        .then((response) => {
          console.log(response);
        })
    }

    btns[1].onclick = function () {
      fetch('http://127.0.0.1:8000/fetch-server', {
        method: 'post',
        headers: {
          name: 'zijian'
        },
        body: 'a=100&b=200'
      })
        .then(response => {
          return response.json();
        })
        .then(response => {
          console.log(response);
        })
    }
  </script>
</body>

</html>
